﻿using PipeDetection.Repository;
using PipeDetection.Model;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PipeDetection.UI.管段
{
    public partial class FrmOpenPipeNet : UIForm2
    {
        public FrmOpenPipeNet()
        {
            InitializeComponent();
        }

   

 
        private void Loaddata()
        {
           
            var dd = Globel.PipeNetAreaRepository.Query();
            Console.WriteLine(  dd.Count);
            uiDataGridView1.DataSource =dd ;
         
        }

  

        private void uiSymbolButton1_Click_1(object sender, EventArgs e)
        {
            if (Globel.GetDlgResult(this, new FrmNewPipeNet(), out object result)) Loaddata();
        }

        private void uiSymbolButton4_Click_1(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void uiSymbolButton3_Click(object sender, EventArgs e)
        {
            if (uiDataGridView1.SelectedIndex != -1)
            {
                Tag = ((List<PipeNetArea>)uiDataGridView1.DataSource)[uiDataGridView1.SelectedIndex];
                DialogResult = DialogResult.OK;
            }
            else
            {
                UIMessageBox.ShowInfo("请先选择项目");
            }
            
        }

        private void FrmOpenPipeNet_Load_1(object sender, EventArgs e)
        {
            Loaddata();
        }

        private void uiSymbolButton2_Click(object sender, EventArgs e)
        {
            if (uiDataGridView1.SelectedIndex != -1)
            {
                var p = ((List<PipeNetArea>)uiDataGridView1.DataSource)[uiDataGridView1.SelectedIndex];
                new FrmNewPipeNet(p).ShowDialog();
                Loaddata();
            }
            else
            {
                UIMessageBox.ShowInfo("请先选择项目");
            }
        }

        private void uiDataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1) {
                Tag = ((List<PipeNetArea>)uiDataGridView1.DataSource)[e.RowIndex];
                DialogResult = DialogResult.OK;
            }
        }
    }
}
